home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Demo / imgbrowse / mac_image.py < prev   
Encoding:
Python Source  |  1996-10-04  |  1.4 KB  |  56 lines  |  [TEXT/Pyth]

  1. """mac_image - Helper routines (hacks) for images"""
  2. import imgformat
  3. import Qd
  4. import time
  5. import struct
  6.  
  7. _fmt_to_mac = {
  8.     imgformat.macrgb16 : (16, 16, 3, 5),
  9. }
  10.  
  11. def mkpixmap(w, h, fmt, data):
  12.     """kludge a pixmap together"""
  13.     fmtinfo = _fmt_to_mac[fmt]
  14.     
  15.     rv = struct.pack("lhhhhhhhlllhhhhlll",
  16.         id(data)+16,
  17.         w*2 + 0x8000,
  18.         0, 0, h, w,
  19.         0,
  20.         0, 0, # XXXX?
  21.         72<<16, 72<<16,
  22.         fmtinfo[0], fmtinfo[1],
  23.         fmtinfo[2], fmtinfo[3],
  24.         0, 0, 0)
  25. ##    print 'Our pixmap, size %d:'%len(rv)
  26. ##    dumppixmap(rv)
  27.     return Qd.RawBitMap(rv)
  28.  
  29. def dumppixmap(data):
  30.     baseAddr, \
  31.         rowBytes, \
  32.         t, l, b, r, \
  33.         pmVersion, \
  34.         packType, packSize, \
  35.         hRes, vRes, \
  36.         pixelType, pixelSize, \
  37.         cmpCount, cmpSize, \
  38.         planeBytes, pmTable, pmReserved \
  39.             = struct.unpack("lhhhhhhhlllhhhhlll", data)
  40.     print 'Base:       0x%x'%baseAddr
  41.     print 'rowBytes:   %d (0x%x)'%(rowBytes&0x3fff, rowBytes)
  42.     print 'rect:       %d, %d, %d, %d'%(t, l, b, r)
  43.     print 'pmVersion:  0x%x'%pmVersion
  44.     print 'packing:    %d %d'%(packType, packSize)
  45.     print 'resolution: %f x %f'%(float(hRes)/0x10000, float(vRes)/0x10000)
  46.     print 'pixeltype:  %d, size %d'%(pixelType, pixelSize)
  47.     print 'components: %d, size %d'%(cmpCount, cmpSize)
  48.     print 'planeBytes: %d (0x%x)'%(planeBytes, planeBytes)
  49.     print 'pmTable:    0x%x'%pmTable
  50.     print 'pmReserved: 0x%x'%pmReserved
  51.     for i in range(0, len(data), 16):
  52.         for j in range(16):
  53.             if i + j < len(data):
  54.                 print '%02.2x'%ord(data[i+j]),
  55.         print
  56.